package org.luxor.commons.mvc.config.properties;

import org.luxor.commons.core.utils.StrKit;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.util.ArrayList;
import java.util.List;

/**
 * 接口签名相关配置
 *
 * @author Mr.yan  @date 2022/11/3
 */
@ConfigurationProperties(prefix = SignatureProperties.PREFIX)
public class SignatureProperties {
    public static final String PREFIX = "spring.signature";

    private final Boolean DEFAULT_ENABLED = Boolean.FALSE;

    private final String DEFAULT_INCLUDE_URIS = "/*";

    private final String DEFAULT_EXCLUDE_URIS = "/actuator/health,/actuator/info," +
            "/swagger-ui.html,/swagger-resources,/swagger-resources/**,/v2/api-docs,/webjars/**";

    /**
     * 是否启用
     */
    private boolean enabled;

    /**
     * 客户端证书配置
     */
    private List<ClientCredential> credentials;

    /**
     * 包含拦截的接口
     */
    private String includeUris;

    /**
     * 排除拦截的接口
     */
    private String excludeUris;

    public SignatureProperties() {
        this.enabled = DEFAULT_ENABLED.booleanValue();
        this.credentials = new ArrayList<>();
        this.includeUris = DEFAULT_INCLUDE_URIS;
        this.excludeUris = DEFAULT_EXCLUDE_URIS;
    }

    public boolean isEnabled() {
        return enabled;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    public List<ClientCredential> getCredentials() {
        return credentials;
    }

    public void setCredentials(List<ClientCredential> credentials) {
        this.credentials = credentials;
    }

    public String getExcludeUris() {
        return excludeUris;
    }

    public void setExcludeUris(String excludeUris) {
        this.excludeUris = excludeUris;
    }

    public String[] excludeUrlPatterns() {
        return getExcludeUris().split(StrKit.COMMA);
    }

    public String getIncludeUris() {
        return includeUris;
    }

    public void setIncludeUris(String includeUris) {
        this.includeUris = includeUris;
    }

    public String[] includeUrlPatterns() {
        return getIncludeUris().split(StrKit.COMMA);
    }
}
